
import re

import requests

fp1 = open('C:\\Users\\tangchenqian\Desktop\\test.txt', "rb")
fp2 = open('C:\\Users\\tangchenqian\Desktop\\pic.txt', "w")
picdataList = []
urlList = []
sum = 0

for i in range(1, 1000):
    line = fp1.readline()
    if not line:
        break
    try:
        s = re.findall(r'src="(.+?)"', line, re.M)
    except Exception as e:
        print(e)
        print(i)
        print(s)
    picurl = s[0]
    # fp2.write(picurl)
    urlList.append(picurl)

for j in range(1,len(urlList)):
    response = requests.get(urlList[j])
    picsize = dict(response.headers).get('Content-Length')
    sum = sum + int(picsize)
averange = sum / len(urlList)
print(averange)

